import ProTable from '@ant-design/pro-table';
import React, {useState} from 'react';
import {defaultPagination, paginationTool} from '@/utils/util';
import {useMount, useRequest} from 'ahooks';
import {Button, Popconfirm, Typography} from 'antd';
import {findByWalletBackPageWithdrawal, withdrawalStatus} from "@/services/ant-design-pro/log";
import {getResult} from "@/services/ant-design-pro/attribute";
import {Link} from 'umi';
const {Paragraph} = Typography;
const getAttr = async (key: string) => {
  return await getResult ( key, 1 );
};
const columns = [
  {
    title: '编号',
    dataIndex: 'id',
    search: false,
    key: 'id',
  },

  {
    title: '经销商',
    dataIndex: 'authName',
    key: 'authName',
    search: true,
  },
  {
    title: '提现金额',
    dataIndex: 'request_amount',
    valueType: 'money',
    key: 'request_amount',
    search: false,
  }
 /* , {
    title: '手续费',
    dataIndex: 'taxes',
    valueType: 'money',
    key: 'taxes',
    search: false,
  }, {
    title: '实际金额',
    dataIndex: 'amount',
    valueType: 'money',
    key: 'amount',
    search: false,
  }*/
  , {
    title: '提现方式',
    dataIndex: 'backName',
    key: 'backName',
    search: false

  },

  {
    title: '状态',
    dataIndex: 'status',
    valueType: 'select',
    key: 'status',
    search: true,
    valueEnum: await getResult ( "paymentwithdrawalStatus", 0 ),

  },

  {
    title: '收款人姓名',
    dataIndex: 'name',
    valueType: 'name',
    key: 'name',
    search: false,
  }, {
    title: '备注',
    dataIndex: 'remark',
    key: 'remark',
    search: false,
  },
  {
    title: "申请时间",
    key: "create_date",
    dataIndex: "create_date",
    valueType: 'dateTime',
    search: false
  },
  {
    title: '更新时间',
    dataIndex: 'update_date',
    valueType: 'dateTime',
    hideInSearch: true,
    key: 'update_date',
  }, {
    title: "操作员",
    key: "operatorName",
    dataIndex: "operatorName",
    search: false,
  }

];

//
const cloneTbale = () => {
  const [pagination, setPagination] = useState<API.Pagination> ( defaultPagination () );
  const {
    run: fetchByPageList,
    refresh,
    data: dataList,
    loading,
  } = useRequest ( findByWalletBackPageWithdrawal, {
    debounceWait: 100,
    manual: true,
  } );

  useMount ( () => {
    columns[12] = {
      title: '操作',
      key: 'option',
      valueType: 'option',
      render: (_: any, row: API.Users, index: number, action: any) => [
        row?.status == 2 ?
          <Popconfirm title={"通过确定吗！"} onConfirm={() => {
            withdrawalStatus ( row?.id, 1 ).then ( res => {
              refresh ()
            } )
          }}>
            <Button type="primary">通过</Button> </Popconfirm> : '',
        row?.status == 2 ?
          <Popconfirm title={"未通过确定吗！"} onConfirm={() => {
            withdrawalStatus ( row?.id, 3 ).then ( res => {
              refresh ()
            } )
          }}>
            <Button type="primary" danger>未通过</Button> </Popconfirm> : '',
        <Link to={"/finance/withdrawalshow?id=" + row?.id}>详细</Link>
      ]
    }

    fetchByPageList ();
  } );
  const formatNumber = (n) => {
    n = n.toString();
    return n[1] ? n : `0${n}`;
  };
  const formatTimeAll = (date: { getFullYear: () => any; getMonth: () => number; getDate: () => any; getHours: () => any; getMinutes: () => any; getSeconds: () => any; }) => {
    const year = date.getFullYear();
    const month = date.getMonth() + 1;
    const day = date.getDate();
    const hour = date.getHours();
    const minute = date.getMinutes();
    const second = date.getSeconds();

    return (
      [year, month, day].map(formatNumber).join("-") +
      " " + [hour, minute, second].map(formatNumber).join(":")
    );
  };

  const getCopyText = (data:any) => {
    //  let data = dataInfo?.data;
    let arr: [any] = []
    arr.push ( "姓名:" + data?.name )
    arr.push ( "订单号:" + data?.sn )
    arr.push ( "提现金额:" + data?.request_amount )
    arr.push ( "申请时间:" + formatTimeAll(new Date(data?.create_date)))
    arr.push ( "提现方式:" + data?.backName )
  //  arr.push ( "卡号:" + data?.bankInfo?.cardNo)
   // arr.push ( "手机号:" + data?.phone)
  //  arr.push ( "地址:" + data?.bankInfo?.address )


    let s = arr.join ( ";\n\t\t" );
    return s;

  }
  return (
    <ProTable
      search={false}
      dataSource={dataList?.data?.list}
      loading={loading}
      pagination={paginationTool ( pagination, dataList?.data?.total, (data1: API.Pagination) => {
        setPagination ( data1 );

        fetchByPageList ( {...data1} );
      } )}
      search={{
        defaultCollapsed: false,
        labelWidth: 'auto',
      }}
      onSubmit={(params) => {
        fetchByPageList ( params );
        console.log ( 'onSubmit', params );
      }}
      cardBordered={true}
      columns={columns}
    />
  );
};

export default cloneTbale;
